/**
 * Created by zqebs on 2016/8/4.
 */
angular.module('Portal').factory('myHttpResponseInterceptor', ['$q', '$location','$cookies', function($q, $location,$cookies) {
    return {
        'responseError': function(response) {
            // do something on error
            if (response.status === 401 && response.data.indexOf('Unauthorized. Redirecting') !== -1 && response.data.indexOf('signin') !== -1) {
                $location.path('/signin');
                //clear cookies
                var cookies = $cookies.getAll();
                angular.forEach(cookies, function (v, k) {
                    $cookies.remove(k,{path:'/'});
                });
                window.location.href = "/signin";

                response.data = 'token expired';
                return $q.reject(response);

            }else{
                return $q.reject(response);
            }
        }
    };
}]);

